package com.ggshily.swf.abc;

import java.io.DataInput;
import java.io.IOException;

/**
 * This entry is a variable length item that is used to define multiname entities used by the bytecode. 
 * There are many kinds of multinames.
 * 
 * @author playfish_chg
 *
 */
public class ABCMultiname
{
	public static final int CONSTANT_QName = 0x07;
	public static final int CONSTANT_QNameA = 0x0D;
	public static final int CONSTANT_RTQName = 0x0F;
	public static final int CONSTANT_RTQNameA = 0x10;
	public static final int CONSTANT_RTQNameL = 0x11;
	public static final int CONSTANT_RTQNameLA = 0x12;
	public static final int CONSTANT_Multiname = 0x09;
	public static final int CONSTANT_MultinameA = 0x0E;
	public static final int CONSTANT_MultinameL = 0x1B;
	public static final int CONSTANT_MultinameLA = 0x1C;
	public static final int CONSTANT_GenericType = 0x1D;

	/**
	 * U8, this field acts as a tag: its value determines how the loader should see the variable-length <code>data</code> field.
	 */
	public short kind;
	// public byte[] data;

	public int ns;
	public int name;
	public int ns_set;

	public String nameStr;
	public ABCNamespace namespace;
	
	
	public ABCMultiname()
	{

	}

	public ABCMultiname(DataInput di, ABCConstantPool constantPool) throws IOException
	{
		kind = ABCUtil.readU8(di);

		switch (kind)
		{
		case CONSTANT_QName:
		case CONSTANT_QNameA:
			ns = ABCUtil.readU30(di);
			name = ABCUtil.readU30(di);
			nameStr = constantPool.strings[name];
			break;
		case CONSTANT_RTQName:
		case CONSTANT_RTQNameA:
			name = ABCUtil.readU30(di);
			nameStr = constantPool.strings[name];
			break;
		case CONSTANT_RTQNameL:
		case CONSTANT_RTQNameLA:
			break;
		case CONSTANT_Multiname:
		case CONSTANT_MultinameA:
			name = ABCUtil.readU30(di);
			nameStr = constantPool.strings[name];
			ns_set = ABCUtil.readU30(di);
			break;
		case CONSTANT_MultinameL:
		case CONSTANT_MultinameLA:
			ns_set = ABCUtil.readU30(di);
			break;
		case CONSTANT_GenericType:
			ABCUtil.readU30(di);
			ABCUtil.readU30(di);
			ABCUtil.readU30(di);
			break;
		default:
			System.err.println("Unknow multiname kind!!!");
			break;
		}
	}
}
